package com.zhiyou.controller;

import java.util.Arrays;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.omg.CORBA.PUBLIC_MEMBER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zhiyou.pojo.Course;
import com.zhiyou.pojo.Speaker;
import com.zhiyou.pojo.Video;
import com.zhiyou.service.SpeakerService;

@Controller
public class SpeakerController {
    @Autowired
    private SpeakerService speakerService;
	@RequestMapping("/showSpeakerList.action")
	public String showVideoList(Model model,HttpSession session){
		
		List<Speaker> list=speakerService.selectAll();
		model.addAttribute("list", list);
		System.out.println(list);
		model.addAttribute("userName", session.getAttribute("userName"));
		return "behind/speakerMgr";
	}
	@RequestMapping("/addSpeaker.action")
	public String addSpeaker(Model model){
		
		List<Speaker> list=speakerService.selectAll();
		model.addAttribute("speakeList", list);
		
		return "behind/addSpeaker";
	}
	@RequestMapping("/saveSpeaker.action")
	public String saveSpeaker(Speaker speaker) {

		speakerService.saveOrUpdate(speaker);
		
		return "redirect:/showSpeakerList.action";
	}
	@RequestMapping("/speakerDel.action")
	@ResponseBody 
	public String deleteById(int id) {

		int result =speakerService.delById(id);
		
		if(result>0){
			return "success";
		}else{
			return "fail";
		}
	}
	@RequestMapping("/delBatchSpeakers.action")
	public String delBatchSpeakerByIds(Integer[] ids){
		
		
		speakerService.delBatchByIds(ids);
		return "redirect:/showSpeakerList.action";
	}
	@RequestMapping("/speakerEdit.action")
	public String editSpeaker(int id, Model model) {

		
		Speaker speaker = speakerService.selectById(id);
		model.addAttribute("speaker", speaker);
		
		List<Speaker> speakerList = speakerService.selectAll();
				
		model.addAttribute("speakerList", speakerList);
	
		
		

		return "behind/addSpeaker";
	}
	
	
}
